package cn.edu.scau.cmi.tangqingning.controll;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import cn.edu.scau.cmi.tangqingning.dao.UserDao;
import cn.edu.scau.cmi.tangqingning.dao.impl.UserDaoImpl;

/**
 * 控制层-删除小组信息的逻辑处理<br>
 * 当客户使用get方式请求Servlet时，Web容器调用doGet方法处理请求，通过调用UserDaoImpl的delGroup方法删除小组
 * @author 周华智
 *@see cn.edu.scau.cmi.tangqingning.dao.impl.UserDaoImpl#delGroup
 */
public class DeleteGroupServlet extends HttpServlet {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	/**
	 * @param request HttpServletRequest
	 * @param response HttpServletResponse
	 * @throws ServletException 如果一个错误发生，则抛出此异常
	 * @throws IOException 如果一个错误发生，则抛出此异常
	 */
	@Override
	public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		this.doPost(request, response);
	}

	/**
	 * 重写doGet方法
	 * @param request HttpServletRequest
	 * @param response HttpServletResponse
	 * @throws ServletException 如果一个错误发生，则抛出此异常
	 * @throws IOException 如果一个错误发生，则抛出此异常
	 */

	@Override
	public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		UserDao userdao = new UserDaoImpl();
		int groupNumber = Integer.parseInt(request.getParameter("groupNumber"));
		boolean flag = userdao.delGroup(groupNumber);
		if (flag) {
			RequestDispatcher dispatch = request.getRequestDispatcher("showAllProData");
			dispatch.forward(request, response);
		} else {
			System.out.println("删除失敗!!");
		}
	}

}
